package algorithm_demo.leetcode;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * 739. 每日温度
 * <a href="https://leetcode.cn/problems/daily-temperatures/">https://leetcode.cn/problems/daily-temperatures/</a>
 * @author Api
 * @date 2023/5/9 23:29
 */
public class Problem_739_DailyTemperatures {
    public static int[] dailyTemperatures(int[] temperatures) {
        Deque<Integer> stack = new ArrayDeque<>();//stack存放的是下标，主要是为了计算
        int[] arr = new int[temperatures.length];//数组默认就是 0，如果stack中还存在数据不用管
        for(int i = 0; i < temperatures.length; i++){
            while(!stack.isEmpty() && temperatures[stack.peek()] < temperatures[i]){
                arr[stack.peek()] = i - stack.pop();
            }
            stack.push(i);
        }
        return arr;
    }


    public static void main(String[] args) {
        int[] arr = new int[]{73,74,75,71,69,72,76,73};
        dailyTemperatures(arr);
    }
}
